import java.util.ArrayList;
import java.util.List;

public class Solution241 {
    public List<Integer> diffWaysToCompute(String expression) {
        List<Integer> numbers=new ArrayList<>();
        List<Character> chars=new ArrayList<>();
        StringBuilder stringBuilder=new StringBuilder();
        for (int i=0;i<expression.length();i++) {
            if (expression.charAt(i) >= '0' && expression.charAt(i) <= '9') {
                stringBuilder.append(expression.charAt(i));
            } else {
                numbers.add(Integer.parseInt(stringBuilder.toString()));
                stringBuilder = new StringBuilder();
                chars.add(expression.charAt(i));
            }
        }
        numbers.add(Integer.parseInt(stringBuilder.toString()));
        return cal(numbers,chars,0,numbers.size()-1);
    }

    private List<Integer> cal(List<Integer> numbers, List<Character> chars, int start, int end){
        List<Integer> set=new ArrayList<>();
        if (start==end){
            set.add(numbers.get(start));
        }else{
            for (int i=start;i<end;i++){
                List<Integer> s1=cal(numbers,chars,start,i);
                List<Integer> s2=cal(numbers,chars,i+1,end);
                for (Integer i1 : s1) {
                    for (Integer i2 : s2) {
                        switch (chars.get(i)){
                            case '+':set.add(i1+i2);
                            break;
                            case '-':set.add(i1-i2);
                            break;
                            case '*':set.add(i1*i2);
                        }
                    }
                }
            }
        }
        return set;
    }

    public static void main(String[] args) {
        System.out.println(new Solution241().diffWaysToCompute("2*3-4*5"));
    }
}
